package com.redteam.models;

import com.redteam.data.beans.Person;
import com.redteam.data.dao.interfaces.DAO;
import com.redteam.data.dao.PersonsDAO;

/**
 *Validates the users username and password
 * @author Anthony
 */
public class AuthorizationModel {

    String userName;
    String password;
    DAO dao;
    Person person;

    /**
     *
     * @param userName
     * @param password
     */
    public AuthorizationModel(String userName, String password) {
        this.userName = userName;
        this.password = password;
        dao = PersonDAO.getInstance();
        dao.
        person = dao.getPersonByUserName(userName);

    }

    /**
     * Checks to see if the user exists.
     * @return Returns True is the user exists and False otherwise.
     */
    public boolean userExists() {
        return (person != null);
    }

    /**
     *
     * @return Returns the person or null if the user name is invalid
     */
    public Person getUser() {
        return person;

    }

    /**
     * Checks if the password typed matches the one in the database
     * @return Returns True if the passwords match and False otherwise.
     */
    public boolean checkPassword() {
        return (password.equals(person.getPassword()));
    }

}
